#include "point.h"
#include <iostream>

point::point()
{}

point::point(double x_, double y_) : x(x_), y(y_)
{
}

sign long_left_turn(const point &p1, const point &p2, const point &p3)
{
    mpq_class p1x = p1.x; mpq_class p1y = p1.y;
    mpq_class p2x = p2.x; mpq_class p2y = p2.y;
    mpq_class p3x = p3.x; mpq_class p3y = p3.y;

    mpq_class res = (p3x - p1x) * (p2y - p1y) - (p3y - p1y) * (p2x - p1x);

    if (res < 0)
        return NEGATIVE;
    else if (res > 0)
        return POSITIVE;
    else
        return EQUAL;
}

sign left_turn(const point& p1, const point& p2, const point& p3)
{
    double tmp1 = (p3.x - p1.x) * (p2.y - p1.y);
    double tmp2 = (p3.y - p1.y) * (p2.x - p1.x);
    double res = tmp1 - tmp2;
    double eps = meps * (std::abs(tmp1) + std::abs(tmp2));

    if (res < -eps)
        return NEGATIVE;
    else if (res > eps)
        return POSITIVE;
    else
        return long_left_turn(p1, p2, p3);
}

std::istream& operator >>(std::istream& in, point& p)
{
    double x, y;
    in >> x >> y;
    p = point(x, y);
    return in;
}

std::ostream& operator <<(std::ostream& out, const point& p)
{
    out << '{' << p.x << ", " << p.y << '}';
    return out;
}
